﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace SnmpForm.SysUser
{
    public partial class frmSysUserModify : frmSysUser
    {
        public frmSysUserModify(DbWrapper.DbDataTypes.User user):base(user)
        {
            InitializeComponent();
        }

        private void buttonSave_Click(object sender, EventArgs e)
        {
            Update(false);
            DbWrapper.DbDataTypes.User user = GetUserInfo();
            if (user != null)
            {
                //是否有修改密码
                if (textBoxPasswd.Enabled)
                {
                    if (textBoxPasswd.Text.Length > 0)
                    {
                        user.password = 
                            BusinessWrapper.User.Instance.Hash(textBoxPasswd.Text);
                    }
                    else
                    {
                        labelError.Text = "密码不能为空";
                        return;
                    }
                }

                bool bSuccess = BusinessWrapper.User.Instance.ModifyUser(user);
                if (bSuccess)
                {
                    MessageBox.Show("修改成功");
                    Close();
                }
                else
                {
                    MessageBox.Show("修改失败");
                }
            }
        }

        private void buttonChPasswd_Click(object sender, EventArgs e)
        {
            textBoxPasswd.Enabled = true;
        }

        private void frmSysUserModify_Load(object sender, EventArgs e)
        {
            textBoxPasswd.Enabled = false;
        }
    }
}
